using UnityEngine;

public class GravityBallFlight : BallFlight
{
	public Vector3 initialPosition
	{
		get
		{
			return base.initialConditions.position;
		}
	}

	public Vector3 initialVelocity
	{
		get
		{
			return base.initialConditions.velocity;
		}
	}

	public override void SetInitialConditions(FlightParams initialConditions, PhysicsBall ball)
	{
		base.initialConditions = initialConditions;
	}

	public override void Reset()
	{
		base.flightTime = 0f;
	}

	public override Vector3 PositionAt(float time)
	{
		return new Vector3(ParabolaPosition(initialPosition.x, initialVelocity.x, gravity.x, time), ParabolaPosition(initialPosition.y, initialVelocity.y, gravity.y, time), ParabolaPosition(initialPosition.z, initialVelocity.z, gravity.z, time));
	}

	protected float ParabolaPosition(float s0, float v0, float g, float time)
	{
		return s0 + g * 0.5f * time * time + v0 * time;
	}

	public override Vector3 Position()
	{
		return PositionAt(base.flightTime);
	}

	public override Vector3 Velocity()
	{
		return VelocityAt(base.flightTime);
	}

	public override Vector3 VelocityAt(float time)
	{
		return initialVelocity + gravity * time;
	}

	public override Vector3 AngularVelocity()
	{
		return base.initialConditions.angularVelocity;
	}

	public override Vector3 AngularVelocityAt(float time)
	{
		return AngularVelocity();
	}

	public float timeToReachHeight(float height)
	{
		MathEx.NullPoints nullPoints = MathEx.FindParabolaNullPoints(gravity.y * 0.5f, initialVelocity.y, initialPosition.y - height);
		if (nullPoints.nullPts.Count == 0)
		{
			return -1f;
		}
		return nullPoints.Max;
	}

	public override void Update(float deltaTime)
	{
		base.flightTime += deltaTime;
	}
}
